﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NetUtilityLib;
using Microsoft.VisualBasic;

namespace DMSMT.Tool
{
    public partial class FilePubMainFrm : Form
    {
        public FilePubMainFrm()
        {
            InitializeComponent();
        }

        private void addTab(string tab)
        {
            TabPage tabPage = new TabPage();
            tabPage.Text = tab;
            FileCopyTool page = new FileCopyTool(tab);
            page.TopLevel = false;
            page.Dock = DockStyle.Fill;
            page.FormBorderStyle = FormBorderStyle.None;
            tabPage.Controls.Add(page);
            page.Show();
            tcMain.TabPages.Add(tabPage);
        }

        private void FilePubMainFrm_Load(object sender, EventArgs e)
        {
            tcMain.TabPages.Clear();
            string[] tabs = Config.GetAppStr("tool.FileCopyTool.sourceDir.tabs").Split(',');
            for (int i = 0; i < tabs.Length; i++)
            {
                string tab = tabs[i];
                if (!string.IsNullOrEmpty(tab))
                    addTab(tab);
            }
        }

        private void FilePubMainFrm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //通过索引访问选项卡
            //tabControl1.TabPages[0]
            ////通过TabPage的Name属性访问选项卡
            //tabControl1.Tabpages["page1"]

            //访问选项卡中的控件
            //tabControl1.TabPages[0].Controls[0];
            //tabControl1.TabPages[0].Controls["formpage"];

            //如果要访问控件中的成员，需要进行类型转换
            //例如，访问Form1中的成员
            //Form1 form = tabControl1.TabPages[0].Controls[0] as Form1;
            //然后通过form来访问Form1的内部成员
            string tabs = "";
            for (int i = 0; i < tcMain.TabPages.Count; i++)
            {
                TabPage tabPage=tcMain.TabPages[i];
                FileCopyTool frm = tabPage.Controls[0] as FileCopyTool;
                string tab = frm.tab;
                tabs += tab + ",";
                frm.SaveConfig();
            }
            tabs.Substring(0, tabs.Length - 1);

            Config.SetAppStr("tool.FileCopyTool.sourceDir.tabs", tabs);
            Config.Refresh();
        }

        private void menuAddTool_Click(object sender, EventArgs e)
        {
            string str = Interaction.InputBox("请输入标签名称", "新建标签", "", 100, 100);
            if (!string.IsNullOrEmpty(str))
            {
                addTab(str);
            }
        }

    }
}
